<?php
/**
*	This class handles all of the email side of the things,
*/
if(!isset($configLoaded))
{
    require './includes/config.inc.php';
}

class Email
{
    /**
    *	This method handles the sending of a users forgotten details
    */
    public function sendForgotPassword($email,$code)
    {
            $to = $email;
            $subject = "Forgotten Password || " . SITE_NAME;
            $message =
"
Hi, you recently requested a forgotten password for " . SITE_NAME . ". Below is the link you need to reset your password, just click it and you will be taken to the password
reset page.

If you have no idea what this email is about then please ignore it and nothing will be changed. If you are concerned someone is trying to access your account, I wouldn't worry
they aren't getting in. Or you can contact the administrator.

*************************** RESET URL ***************************
Reset URL: " . DOMAIN_NAME . "forgotPassword.php?email=$email&reset=$code
*****************************************************************

Thanks " . SITE_NAME . " management";

            // Some random header stuff
            $headers = 'MIME-Version: 1.0' . "\r\n";
            $headers .= 'From: Password Reset <no-reply@onlyelitejobs.com>\r\n';

            if(mail($to,$subject,$message,$headers))
            {
                    return true;
            }
    }

    /**
    *	This method handles the sending of a registration email
    */
    public function registerSuccess($companyName,$contactName,$email,$password)
    {
            $to = $email;
            $subject = "Registration Success || " . SITE_NAME;
            $message =
"
Hello $contactName,

Welcome to ".SITE_NAME.". This is just a quick email to show you a few details just incase you have forgotten already.

EMAIL: $email
PASSWORD: $password

Thanks for registering, and see you soon.";

            $headers = 'MIME-Version: 1.0' . "\r\n";
            $headers .= 'From: Account Creation <no-reply@onlyelitejobs.com>';

            if(mail($to,$subject,$message,$headers))
            {
                    return true;
            }
    }

	/**
    *	This method handles the Application email with file attachment
    */
	public function sendResume($to_name,$to_email,$from_name,$from_email,$attachment_name,$data,$letter,$subject) {
		
		//Let's start our headers
		$headers = "From: $from_name<$from_email>\n";
		$headers .= "Reply-To: <$from_email>\n";
		$headers .= "MIME-Version: 1.0\n";
		$headers .= "Content-Type: multipart/related; type=\"multipart/alternative\"; boundary=\"----=MIME_BOUNDRY_main_message\"\n";
		$headers .= "X-Sender: $from_name<$from_email>\n";
		$headers .= "X-Mailer: PHP4\n";
		$headers .= "X-Priority: 3\n"; //1 = Urgent, 3 = Normal
		$headers .= "Return-Path: <$from_email>\n";
		$headers .= "This is a multi-part message in MIME format.\n";
		$headers .= "------=MIME_BOUNDRY_main_message \n";
		$headers .= "Content-Type: multipart/alternative; boundary=\"----=MIME_BOUNDRY_message_parts\"\n";
		
		$message = "------=MIME_BOUNDRY_message_parts\n";
		$message .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
		$message .= "Content-Transfer-Encoding: quoted-printable\n";
		$message .= "\n";
		/* Add our message, in this case it's plain text. You could also add HTML by changing the Content-Type to text/html */
		$message .= "$letter\n";
		$message .= "\n";
		$message .= "------=MIME_BOUNDRY_message_parts--\n";
		$message .= "\n";
		$message .= "------=MIME_BOUNDRY_main_message\n";
		$message .= "Content-Type: application/octet-stream;\n\tname=\"" . $attachment_name . "\"\n";
		$message .= "Content-Transfer-Encoding: base64\n";
		$message .= "Content-Disposition: attachment;\n\tfilename=\"" . $attachment_name . "\"\n\n";
		$message .= $data; //The base64 encoded message
		$message .= "\n";
		$message .= "------=MIME_BOUNDRY_main_message--\n";
		
		// send the message
		require_once 'classes/Login.php';
    	$Login = new Login();
		include 'includes/header.inc.php';
		/*Send the email and produce message page*/
/*mail("$to_name<$to_email>", $subject, $message, $headers);*/
		print "Form Submitted. Thank you for applying.";
		/*Option to return to the last search result*/
			include ('classes/JobPost.php');
			$JobPost = new JobPost();
			$last = $JobPost->getLastSearch();
			$returnMessage = "<br/><br/><a href='/sandbox1/search.php?country=".$last['country']."&state1=".$last['state']."&city=";
			$returnMessage .= $last['city']."&jobCat=".$last['jobCat']."'>Return to Search</a>";
			echo $returnMessage;
		include 'includes/footer.inc.php';
	}
	
	/**
    *	This method handles the Application email with file attachment
    */
	public function sendResumeBasic($to_name,$to_email,$from_name,$from_email,$letter,$subject) {
		$headers = "From: $from_name<$from_email>\n";
		$headers .= "Reply-To: <$from_email>\n";
		
		// send the message
		require_once 'classes/Login.php';
    	$Login = new Login();
		include 'includes/header.inc.php';
		/*Send the email and produce message page*/
/*mail("$to_name<$to_email>", $subject, $letter, $headers);*/
		print "Form Submitted. Thank you for applying.";
		/*Option to return to the last search result*/
			include ('classes/JobPost.php');
			$JobPost = new JobPost();
			$last = $JobPost->getLastSearch();
			$returnMessage = "<br/><br/><a href='/sandbox1/search.php?country=".$last['country']."&state1=".$last['state']."&city=";
			$returnMessage .= $last['city']."&jobCat=".$last['jobCat']."'>Return to Search</a>";
			echo $returnMessage;
		include 'includes/footer.inc.php';
	}
}

?>